//appbar,顶部标题页面
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

///包含点击事件的text
class TextClickView extends StatelessWidget {
  final String title;
  final VoidCallback? rightClick;
  double get _padding => isTitleRight ? 16.0 : 0.0;
  final Color color;
  final double fontSize;
  final FontWeight fontWeight;
  final bool isTitleRight;

  ///title 为空时，按钮不显示
  TextClickView(
      {required this.title,
      this.rightClick,
      this.isTitleRight = true,
      this.color = const Color(0xFF333333),
      this.fontSize = 14,
      this.fontWeight = FontWeight.w500});

  @override
  Widget build(BuildContext context) {
    final containView = Container(
      alignment: Alignment.centerRight,
      padding: defaultTargetPlatform == TargetPlatform.iOS
          ? EdgeInsets.only(left: _padding)
          : EdgeInsets.all(_padding),
      child: Text(
        title,
        style: TextStyle(
          color: color,
          fontSize: fontSize,
          fontWeight: fontWeight,
        ),
      ),
    );
    return GestureDetector(
      child: UnconstrainedBox(
        constrainedAxis: Axis.vertical,
        child: containView,
      ),
      onTap: rightClick,
    );
  }
}
